#!/bin/bash

exec 1>/dev/null

start_flag_file=`mktemp`
show_progress_bar()
{
    touch $start_flag_file
    while [ 1 == 1 -a -f $start_flag_file ]; do
        echo -n "." > /dev/stderr
        sleep 1
    done
}

stop_progress_bar()
{
    rm -rf $start_flag_file 2>&1 > /dev/null
}


test_repo()
{
    TEMPDIR=`mktemp -d`

    cd $TEMPDIR
    echo -n "test repo: " > /dev/stderr
    show_progress_bar &
    repo init -u https://gitee.com/tmjl_service/repo_test_manifest.git -b master 2>&1 > /dev/null && repo sync 2>&1 > /dev/null &

    wait $!
    stop_progress_bar
    if [ -f repo_env_success ]; then
        echo "success" > /dev/stderr
    else
        echo "fail" > /dev/stderr
    fi
    cd ~; rm -rf $TEMPDIR 2>&1 > /dev/null
}

test_cmd()
{
    echo -n "test $1: " > /dev/stderr
    $1 --version 2>&1 > /dev/null
    if [ $? == 0 ]; then
        echo "success" > /dev/stderr
    else
        $1 -v 2>&1 > /dev/null
        if [ $? == 0 ]; then
            echo "success" > /dev/stderr
        else
            $1 -version 2>&1 > /dev/null
            if [ $? == 0 ]; then
                echo "success" > /dev/stderr
            else
                echo "fail" > /dev/stderr
            fi
        fi
    fi
}

test_cmd git
test_cmd gcc
test_cmd g++
test_cmd aos
test_cmd java
test_repo